﻿<%@ Page Language="C#" MasterPageFile="~/manager/page/ManagerMasterPage.Master" AutoEventWireup="true" CodeBehind="popup.aspx.cs" Inherits="Com.Web.coffinegurunaru.manager.banner.popup"%>
<%@ Register TagPrefix="UC" TagName="Menu" Src="~/manager/banner/menu.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="phContent" runat="server">

<hr />
<br />
<table>
<tr>
	<td valign="top">
		<UC:Menu ID="Menu1" SubPageType=2 runat="server" />
	</td>
	<td style="width:20px;"></td>
	<td style="text-align:center;">
		<div id="m_PopupAdd">
		<table cellpadding="0" cellspacing="1" style="background-color:Gray; text-align:left; width:100%;">
		<tr style="height:30px;">
			<td style="background-color:Silver; text-align:center; width:100px;">넓이</td>
			<td style="background-color:White; ">&nbsp;<input type="text" class="m_Width" style="width:50px;" maxlength="5"/>px</td>
			<td style="background-color:Silver; text-align:center; width:100px;">높이</td>
			<td style="background-color:White; ">&nbsp;<input type="text" class="m_Height" style="width:50px;" maxlength="5"/>px</td>
		</tr>
		<tr>
			<td style="background-color:Silver; text-align:center; width:100px;">왼쪽</td>
			<td style="background-color:White; ">&nbsp;<input type="text" class="m_Left" style="width:50px;" maxlength="5" value="0"/>px</td>
			<td style="background-color:Silver; text-align:center; width:100px;">위쪽</td>
			<td style="background-color:White; ">&nbsp;<input type="text" class="m_Top" style="width:50px;" maxlength="5" value="0"/>px</td>
		</tr>
		<tr style="height:30px;">
			<td style="background-color:Silver; text-align:center; width:100px;">Popup 내용</td>
			<td style="background-color:White;  text-align:left;" colspan="3">&nbsp;<select class="m_PopupType"><option value="1">Image</option><option value="2">HTML</option></select></td>
		</tr>
		<tr style="height:30px;">
			<td style="background-color:Silver; text-align:center; width:100px;">ImageURL</td>
			<td style="background-color:White;  text-align:left;" colspan="3">&nbsp;<input type="text" class="m_ImageURL" readonly="readonly" style="width:150px;" /><input type="button" value="이미지선택" class="m_btnImage"/></td>
		</tr>
		<tr style="height:30px;">
			<td style="background-color:Silver; text-align:center; width:100px;">LinkURL</td>
			<td style="background-color:White;  text-align:left;" colspan="3">&nbsp;<input type="text" class="m_LinkURL" style="width:500px;" /></td>
		</tr>
		<tr style="height:30px;">
			<td style="background-color:Silver; text-align:center; width:100px;">HTML</td>
			<td style="background-color:White;  text-align:left;" colspan="3">&nbsp;<textarea cols="50" rows="5" class="m_HTML"></textarea></td>
		</tr>
		<tr style="height:30px;">
			<td style="background-color:Silver; text-align:center; width:100px;">다시 열지 않기</td>
			<td style="background-color:White;  text-align:left;" colspan="3">&nbsp;<select class="m_IsCookie"><option value="1">다시열지않기</option><option value="2">계속열림</option></select></td>
		</tr>
		<tr style="height:30px;">
			<td style="background-color:White;  text-align:center;" colspan="4"><input type="button" value="저장" class="m_btnSave" />&nbsp;&nbsp;<input type="button" value="미리보기" class="m_btnView" /></td>
		</tr>
		</table>
		</div>
		
		<br />
		<div style="color:Red">실제 팝업은 최근 5개만 열립니다.</div>
		<br />
<table width="100%">
<tr>
	<td align="center">
		<div id="m_PoupList" ></div>
	</td>
</tr>
</table>

	</td>
</tr>
</table>


<script language="javascript" type="text/javascript">
(function($) {
	$.Popup = {};
	
	$.Popup = {
		$tr : null,
		Win : null,
		Init : function() {
			$("#m_PopupAdd input.m_btnView").click(function() {
				$.Popup.Open( $("#m_PopupAdd") );
			});
			
			$("#m_PopupAdd input.m_btnImage").click(function() {
				$.Popup.FileOpen();
			});
			
			$("#m_PopupAdd input.m_btnSave").click(function() {
				$.Popup.Create();
			});
			
			$.Popup.GetList();
		},
		
		FileOpen : function()
		{
			$.manager.fileopen(6, "$.Popup.FileOpen_Callback");
		},
		
		FileOpen_Callback : function( imageurl )
		{
			$("#m_PopupAdd input.m_ImageURL").val( imageurl );
		},
		
		
		FileOpen_Modify : function( $elem )
		{ 
			$.Popup.$tr = $elem
			$.manager.fileopen(6, "$.Popup.FileOpen_Modify_Callback");
		},
		
		FileOpen_Modify_Callback : function( imageurl )
		{
			$.Popup.$tr.find("input.m_ImageURL").val( imageurl )
		},
		
		Create : function() {
			var height = $("#m_PopupAdd input.m_Height").val();
			var width = $("#m_PopupAdd input.m_Width").val();
			var top = $("#m_PopupAdd input.m_Top").val();
			var left = $("#m_PopupAdd input.m_Left").val();
			var PopupType = $("#m_PopupAdd select.m_PopupType").val();
			var imageurl = $("#m_PopupAdd input.m_ImageURL").val();
			var HTML = $("#m_PopupAdd textarea.m_HTML").val();
			var isCookie = $("#m_PopupAdd select.m_IsCookie").val();
			var LinkURL = $("#m_PopupAdd input.m_LinkURL").val();
			
			height = $.trim(height) == "0" ? "" : height;
			width = $.trim(width) == "0" ? "" : width;
			top = $.trim(top) == "" ? "0" : top;
			left = $.trim(left) == "" ? "0" : left;
			
			if ( height == "" )
			{
				alert( "높이를 입력하세요");
				return false;
			}
			
			if ( width == "" )
			{
				alert( "넓이를 입력하세요");
				return false;
			}
			
			$("#m_PopupAdd").ajaxNet(
			"/manager/banner/popupMethod.aspx?_vb=Create",
			{
				"Width" : width,
				"Height" : height,
				"Left" : left,
				"Top" : top,
				"PopupType" : PopupType,
				"ImageURL" : imageurl,
				"LinkURL" : LinkURL,
				"HTML" : HTML,
				"IsCookie" : isCookie
			}, function(results, context)
			{
				alert('등록되었습니다.');
				$.Popup.GetList();
			});
		},
		
		Modify : function( $elem ) {
			var seqNo = $elem.tagdata().SeqNo;
			var height = $elem.find("input.m_Height").val();
			var width = $elem.find("input.m_Width").val();
			var top = $elem.find("input.m_Top").val();
			var left = $elem.find("input.m_Left").val();
			var PopupType = $elem.find("select.m_PopupType").val();
			var imageurl = $elem.find("input.m_ImageURL").val();
			var HTML = $elem.find("textarea.m_HTML").val();
			var isCookie = $elem.find("select.m_IsCookie").val();
			var LinkURL = $elem.find("input.m_LinkURL").val();

			$("#m_PopupAdd").ajaxNet(
			"/manager/banner/popupMethod.aspx?_vb=Modify",
			{
				"SeqNo" : seqNo,
				"Width" : width,
				"Height" : height,
				"Left" : left,
				"Top" : top,
				"PopupType" : PopupType,
				"ImageURL" : imageurl,
				"LinkURL" : LinkURL,
				"HTML" : HTML,
				"IsCookie" : isCookie
			}, function(results, context)
			{
				alert('수정되었습니다.');
				$.Popup.GetList();
			});
		},
		
		Remove : function( $elem ) {
			var seqNo = $elem.tagdata().SeqNo;
			if ( confirm( "정말로 삭제하시겠습니까?") ) {
				$("#m_PopupAdd").ajaxNet(
				"/manager/banner/popupMethod.aspx?_vb=Remove",
				{
					"SeqNo" : seqNo
				}, function(results, context)
				{
					alert('삭제되었습니다.');
					$.Popup.GetList();
				});
			}
		},
		
		GetList : function() {
			$("#m_PoupList").ajaxNet(
			"/manager/banner/popupMethod.aspx?_vb=GetList",
			{
				"PageNo" : 1,
				"PageSize" : 100
			}, function(results, context)
			{
				$("#m_PoupList").html(results);
				
				$("#m_PoupList input.m_btnImage").click(function() {
					$.Popup.FileOpen_Modify( $(this).closest("tr") );
				});
				
				$("#m_PoupList input.m_btnModify").click(function() {
					$.Popup.Modify( $(this).closest("tr") );
				});
				
				$("#m_PoupList input.m_btnRemove").click(function() {
					$.Popup.Remove( $(this).closest("tr") );
				});
				
				$("#m_PoupList input.m_btnView").click(function() {
					$.Popup.Open( $(this).closest("tr") );
				});
			});
		},
		
		Open : function( $elem ) {
			var height = $elem.find("input.m_Height").val();
			var width = $elem.find("input.m_Width").val();
			var top = $elem.find("input.m_Top").val();
			var left = $elem.find("input.m_Left").val();
			var PopupType = $elem.find("select.m_PopupType").val();
			var imageurl = $elem.find("input.m_ImageURL").val();
			var designHTML = $elem.find("textarea.m_HTML").val();
			var isCookie =  $elem.find("select.m_IsCookie").val();
			var setValue = "";
			var html = "";

			height = $.trim(height) == "0" ? "" : parseInt(height, 10 ) + ( isCookie == 1 ? 40 : 0 );
			width = $.trim(width) == "0" ? "" : width;
			top = $.trim(top) == "0" ? "" : top;
			left = $.trim(left) == "0" ? "" : left;
			
			if ( height == "" )
			{
				alert( "높이를 입력하세요");
				return false;
			}
			
			if ( width == "" )
			{
				alert( "넓이를 입력하세요");
				return false;
			}
			
			setValue += "width=" + width;
			setValue += ",height=" + height;
			setValue += top == "" ? "" : ",top=" + top;
			setValue += left == "" ? "" : ",left=" + left;
			setValue += ",toolbar=no,menubar=no,location=no, scrollbars=no, status=no, resizable=no";
			
			if ( PopupType == 1 )
			{
				if ( imageurl != "" )
				{
					html += "<html><head><title>커핀그루나루</title><link rel=StyleSheet href='/css/style.css' type=text/css /></head><body><div><img src='" + imageurl + "'></div>";
					if ( isCookie == 1 )
					{
						html += "<table style='width:100%; height:40px; background-color:#eeeeee; text-align:right;'><tr><td><input type='checkbox'> 하루동안 창을 열지 않습니다.</td></tr></table>";
					}
					
					html += "</body></html>";
				}
			} else  {
				html += "<html><head><title>커핀그루나루</title><link rel=StyleSheet href='/css/style.css' type=text/css /></head><body>";
				html += designHTML
				if ( isCookie == 1 )
				{
					html += "<table style='width:100%; height:40px; background-color:#eeeeee; text-align:right;'><tr><td><input type='checkbox'> 하루동안 창을 열지 않습니다.</td></tr></table>";
				}
				html += "</body></html>";
			}
			
			if ( $.Popup.Win != null )
			{
				if ( typeof ( $.Popup.Win.document ) == "object")
					$.Popup.Win.close();
			}
			$.Popup.Win = window.open("about:blank", "manager", setValue );
			
			if ( html != "" )
			{
				try
				{
					$.Popup.Win.document.write( html );
				}
				catch (e)
				{
					alert( "창이 열려 있습니다. \r\n 창을 닫으세요!!!");
				}
			}
		}
	}
	
	$(function() {
		$.Popup.Init();
	});
})(jQuery);
</script>

</asp:Content>
